dependencies = [
"advapi32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "docopt 0.6.56 (registry+https://github.com/rust-lang/crates.io-index)",
+ "docopt 0.6.57 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "flate2 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2-curl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "glob 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "flate2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2-curl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glob 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git)",
"kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num_cpus 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
"registry 0.1.0",
- "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "tar 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "tempdir 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "term 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tar 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "time 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
- "toml 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "docopt"
-version = "0.6.56"
+version = "0.6.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
[[package]]
name = "flate2"
-version = "0.2.4"
+version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
[[package]]
name = "gcc"
-version = "0.3.3"
+version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "git2"
-version = "0.2.6"
+version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "git2-curl"
-version = "0.2.2"
+version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glob"
-version = "0.2.7"
+version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hamcrest"
version = "0.1.0"
-source = "git+https://github.com/carllerche/hamcrest-rust.git#80e7a1cbd6db9ec20bb1d61920e55a1af91a9eb2"
+source = "git+https://github.com/carllerche/hamcrest-rust.git#0a87716b6fe9a3feb4afc829923e0121285b8c50"
[[package]]
name = "kernel32-sys"
[[package]]
name = "libgit2-sys"
-version = "0.2.8"
+version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "libssh2-sys 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libssh2-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
[[package]]
name = "libssh2-sys"
-version = "0.1.15"
+version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num_cpus"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libressl-pnacl-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pkg-config"
-version = "0.3.2"
+version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
[[package]]
name = "rand"
-version = "0.3.3"
+version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
version = "0.1.0"
dependencies = [
"curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
-version = "0.3.10"
+version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
[[package]]
name = "tar"
-version = "0.2.7"
+version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tempdir"
-version = "0.3.3"
+version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "rand 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
-version = "0.2.4"
+version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
[[package]]
name = "time"
-version = "0.1.22"
+version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
-version = "0.1.19"
+version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
threadpool = "0.1.1"
libc = "0.1.2"
registry = { path = "src/registry" }
+num_cpus = "0.1"
[target.i686-pc-windows-gnu]
dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" }
-#![feature(core, exit_status, fs_ext)]
+#![cfg_attr(unix, feature(fs_ext))]
extern crate cargo;
extern crate env_logger;
}
fn find_closest(cmd: &str) -> Option<String> {
- match list_commands().iter()
- // doing it this way (instead of just .min_by(|c|
- // c.lev_distance(cmd))) allows us to only make
- // suggestions that have an edit distance of
- // 3 or less
- .map(|c| (lev_distance(&c, cmd), c))
- .filter(|&(d, _): &(usize, &String)| d < 4)
- .min_by(|&(d, _)| d) {
- Some((_, c)) => {
- Some(c.to_string())
- },
- None => None
+ let cmds = list_commands();
+ // Only consider candidates with a lev_distance of 3 or less so we don't
+ // suggest out-of-the-blue options.
+ let mut filtered = cmds.iter().map(|c| (lev_distance(&c, cmd), c))
+ .filter(|&(d, _)| d < 4)
+ .collect::<Vec<_>>();
+ filtered.sort_by(|a, b| a.0.cmp(&b.0));
+
+ if filtered.len() == 0 {
+ None
+ } else {
+ Some(filtered[0].1.to_string())
}
}
}
#[cfg(windows)]
fn is_executable(path: &Path) -> bool {
- fs::metadata(path).map(|m| m.is_file()) == Ok(true)
+ fs::metadata(path).map(|m| m.is_file()).unwrap_or(false)
}
/// Get `Command` to run given command.
use std::path::Path;
+use std::error::Error;
use cargo::core::{Package, Source};
use cargo::util::{CliResult, CliError, Config};
use std::collections::HashMap;
-use std::env;
use std::fs::File;
use std::io::prelude::*;
+use std::process;
-use toml;
use cargo::util::{CliResult, Config};
+use rustc_serialize::json;
+use toml;
pub type Error = HashMap<String, String>;
let file = File::open(&args.flag_manifest_path);
match file.and_then(|mut f| f.read_to_string(&mut contents)) {
Ok(_) => {},
- Err(e) => return fail("invalid", &format!("error reading file: {}", e))
+ Err(e) => fail("invalid", &format!("error reading file: {}", e))
};
match toml::Parser::new(&contents).parse() {
- None => return fail("invalid", "invalid-format"),
+ None => fail("invalid", "invalid-format"),
Some(..) => {}
};
Ok(Some(h))
}
-fn fail(reason: &str, value: &str) -> CliResult<Option<Error>>{
+fn fail(reason: &str, value: &str) -> ! {
let mut h = HashMap::new();
h.insert(reason.to_string(), value.to_string());
- env::set_exit_status(1);
- Ok(Some(h))
+ println!("{}", json::encode(&h).unwrap());
+ process::exit(1)
}
use std::cmp::Ordering;
-use std::error::{Error, FromError};
+use std::error::Error;
use std::fmt::{self, Formatter};
use std::hash::Hash;
use std::hash;
fn is_human(&self) -> bool { true }
}
-impl FromError<PackageIdError> for Box<CargoError> {
- fn from_error(t: PackageIdError) -> Box<CargoError> { Box::new(t) }
+impl From<PackageIdError> for Box<CargoError> {
+ fn from(t: PackageIdError) -> Box<CargoError> { Box::new(t) }
}
#[derive(PartialEq, Eq, Hash, Clone, RustcEncodable, Debug)]
}
}
}
- let mut parts = spec.splitn(1, ':');
+ let mut parts = spec.splitn(2, ':');
let name = parts.next().unwrap();
let version = match parts.next() {
Some(version) => Some(try!(Version::parse(version).map_err(human))),
}));
match frag {
Some(fragment) => {
- let mut parts = fragment.splitn(1, ':');
+ let mut parts = fragment.splitn(2, ':');
let name_or_version = parts.next().unwrap();
match parts.next() {
Some(part) => {
// form `foo` and we need to recurse to enable the feature `foo` for our
// own package, which may end up enabling more features or just enabling
// a dependency.
- let mut parts = feat.splitn(1, '/');
+ let mut parts = feat.splitn(2, '/');
let feat_or_package = parts.next().unwrap();
match parts.next() {
Some(feat) => {
/// 656c58fb7c5ef5f12bc747f".to_string());
/// ```
pub fn from_url(string: String) -> SourceId {
- let mut parts = string.splitn(1, '+');
+ let mut parts = string.splitn(2, '+');
let kind = parts.next().unwrap();
let url = parts.next().unwrap();
}
for (feature, list) in features.iter() {
for dep in list.iter() {
- let mut parts = dep.splitn(1, '/');
+ let mut parts = dep.splitn(2, '/');
let dep = parts.next().unwrap();
let is_reexport = parts.next().is_some();
if !is_reexport && features.get(dep).is_some() { continue }
#![deny(unused)]
-#![feature(os, std_misc, core, path_relative_from, collections)]
-#![feature(io, str_words, exit_status, fs_time, convert)]
+#![feature(fs_time)]
#![cfg_attr(test, deny(warnings))]
#[cfg(test)] extern crate hamcrest;
#[macro_use] extern crate log;
-extern crate rustc_serialize;
extern crate curl;
extern crate docopt;
extern crate flate2;
extern crate git2;
extern crate glob;
extern crate libc;
+extern crate num_cpus;
extern crate regex;
+extern crate registry;
+extern crate rustc_serialize;
extern crate semver;
extern crate tar;
extern crate term;
extern crate toml;
extern crate url;
-extern crate registry;
-
use std::env;
use std::error::Error;
use std::io::prelude::*;
with --verbose.".to_string(), BLACK);
}
- std::env::set_exit_status(exit_code);
+ std::process::exit(exit_code);
}
fn handle_cause(mut cargo_err: &CargoError, shell: &mut MultiShell) -> bool {
fn rm_rf(path: &Path) -> CargoResult<()> {
let m = fs::metadata(path);
- if m.as_ref().map(|s| s.is_dir()) == Ok(true) {
+ if m.as_ref().map(|s| s.is_dir()).unwrap_or(false) {
try!(fs::remove_dir_all(path).chain_error(|| {
human("could not remove build directory")
}));
use std::collections::HashMap;
use std::default::Default;
-use std::num::ToPrimitive;
use std::path::{Path, PathBuf};
use std::sync::Arc;
-> CargoResult<ops::BuildConfig> {
let cfg_jobs = match try!(config.get_i64("build.jobs")) {
Some((n, p)) => {
- match n.to_u32() {
- Some(n) => Some(n),
- None if n <= 0 => {
- return Err(human(format!("build.jobs must be positive, \
- but found {} in {:?}", n, p)));
- }
- None => {
- return Err(human(format!("build.jobs is too large: \
- found {} in {:?}", n, p)));
- }
+ if n <= 0 {
+ return Err(human(format!("build.jobs must be positive, \
+ but found {} in {:?}", n, p)));
+ } else if n >= u32::max_value() as i64 {
+ return Err(human(format!("build.jobs is too large: \
+ found {} in {:?}", n, p)));
+ } else {
+ Some(n as u32)
}
}
None => None,
};
- #[allow(deprecated)]
- fn num_cpus() -> u32 { ::std::os::num_cpus() as u32 }
- let jobs = jobs.or(cfg_jobs).unwrap_or(num_cpus());
+ let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32);
let mut base = ops::BuildConfig {
jobs: jobs,
requested_target: target.clone(),
if list {
let root = pkg.root();
let mut list: Vec<_> = try!(src.list_files(&pkg)).iter().map(|file| {
- file.relative_from(&root).unwrap().to_path_buf()
+ util::without_prefix(&file, &root).unwrap().to_path_buf()
}).collect();
list.sort();
for file in list.iter() {
let root = pkg.root();
for file in try!(src.list_files(pkg)).iter() {
if &**file == dst { continue }
- let relative = file.relative_from(&root).unwrap();
+ let relative = util::without_prefix(&file, &root).unwrap();
let relative = try!(relative.to_str().chain_error(|| {
human(format!("non-utf8 path in source directory: {}",
relative.display()))
use std::collections::HashSet;
-use std::error::FromError;
use std::fs::{self, File};
use std::io::prelude::*;
use std::io;
fn walk<F>(path: &Path, callback: &mut F) -> CargoResult<()>
where F: FnMut(&Path) -> CargoResult<bool>
{
- if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) {
+ if !fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false) {
return Ok(())
}
Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => {
return Ok(())
}
- Err(e) => return Err(FromError::from_error(e)),
+ Err(e) => return Err(From::from(e)),
};
for dir in dirs {
let dir = try!(dir).path();
use std::path::Path;
use ops::{self, ExecEngine, CompileFilter};
-use util::{CargoResult, human, process, ProcessError};
+use util::{self, CargoResult, human, process, ProcessError};
use core::source::Source;
use sources::PathSource;
let compile = try!(ops::compile(manifest_path, options));
let exe = &compile.binaries[0];
- let exe = match exe.relative_from(config.cwd()) {
+ let exe = match util::without_prefix(&exe, config.cwd()) {
Some(path) => path,
None => &**exe,
};
use std::collections::{HashMap, HashSet};
-use std::ffi::AsOsStr;
+use std::ffi::OsStr;
use std::path::PathBuf;
use semver::Version;
}
/// See `process`.
- pub fn target_process<T: AsOsStr + ?Sized>(&self, cmd: &T, pkg: &Package)
+ pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
-> CargoResult<CommandPrototype> {
- self.process(CommandType::Target(cmd.as_os_str().to_os_string()), pkg)
+ self.process(CommandType::Target(cmd.as_ref().to_os_string()), pkg)
}
/// See `process`.
- pub fn host_process<T: AsOsStr + ?Sized>(&self, cmd: &T, pkg: &Package)
+ pub fn host_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
-> CargoResult<CommandPrototype> {
- self.process(CommandType::Host(cmd.as_os_str().to_os_string()), pkg)
+ self.process(CommandType::Host(cmd.as_ref().to_os_string()), pkg)
}
/// Prepares a new process with an appropriate environment to run against
// This is also the location where we provide feedback into the build
// state informing what variables were discovered via our script as
// well.
- let output = try!(str::from_utf8(&output.stdout).chain_error(|| {
+ let output = try!(str::from_utf8(&output.stdout).map_err(|_| {
human("build script output was not valid utf-8")
}));
let parsed_output = try!(BuildOutput::parse(output, &pkg_name));
let whence = format!("build script of `{}`", pkg_name);
for line in input.lines() {
- let mut iter = line.splitn(1, |c| c == ':');
+ let mut iter = line.splitn(2, ':');
if iter.next() != Some("cargo") {
// skip this line since it doesn't start with "cargo:"
continue;
};
// getting the `key=value` part of the line
- let mut iter = data.splitn(1, |c| c == '=');
+ let mut iter = data.splitn(2, '=');
let key = iter.next();
let value = iter.next();
let (key, value) = match (key, value) {
pub fn parse_rustc_flags(value: &str, whence: &str)
-> CargoResult<(Vec<PathBuf>, Vec<String>)> {
- // TODO: some arguments (like paths) may contain spaces
let value = value.trim();
- let mut flags_iter = value.words();
+ let mut flags_iter = value.split(|c: char| c.is_whitespace())
+ .filter(|w| w.chars().any(|c| !c.is_whitespace()));
let (mut library_links, mut library_paths) = (Vec::new(), Vec::new());
loop {
let flag = match flags_iter.next() {
use std::collections::HashMap;
-use std::ffi::{AsOsStr, OsString};
+use std::ffi::{OsStr, OsString};
use std::fmt;
use std::path::Path;
use std::process::Output;
pub fn get_type(&self) -> &CommandType { &self.ty }
- pub fn arg<T: AsOsStr + ?Sized>(&mut self, arg: &T) -> &mut CommandPrototype {
+ pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut CommandPrototype {
self.builder.arg(arg);
self
}
- pub fn args<T: AsOsStr>(&mut self, arguments: &[T]) -> &mut CommandPrototype {
+ pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut CommandPrototype {
self.builder.args(arguments);
self
}
- pub fn cwd<T: AsOsStr + ?Sized>(&mut self, path: &T) -> &mut CommandPrototype {
+ pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut CommandPrototype {
self.builder.cwd(path);
self
}
- pub fn env<T: AsOsStr + ?Sized>(&mut self, key: &str, val: &T)
- -> &mut CommandPrototype {
+ pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T)
+ -> &mut CommandPrototype {
self.builder.env(key, val);
self
}
let absolute = pkg.root().join(target.src_path());
let cwd = cx.config.cwd();
if absolute.starts_with(cwd) {
- absolute.relative_from(cwd).map(|s| s.to_path_buf()).unwrap_or(absolute)
+ util::without_prefix(&absolute, cwd).map(|s| {
+ s.to_path_buf()
+ }).unwrap_or(absolute)
} else {
absolute
}
use core::Source;
use sources::PathSource;
use ops::{self, ExecEngine, ProcessEngine, Compilation};
-use util::{CargoResult, ProcessError};
+use util::{self, CargoResult, ProcessError};
pub struct TestOptions<'a, 'b: 'a> {
pub compile_opts: ops::CompileOptions<'a, 'b>,
let cwd = config.cwd();
for &(_, ref exe) in &compile.tests {
- let to_display = match exe.relative_from(&cwd) {
+ let to_display = match util::without_prefix(exe, &cwd) {
Some(path) => path,
None => &**exe,
};
use core::{Package, PackageId, Summary, SourceId, Source, Dependency, Registry};
use ops;
-use util::{CargoResult, internal, internal_error, human, ChainError, Config};
+use util::{self, CargoResult, internal, internal_error, human, ChainError, Config};
pub struct PathSource<'a, 'b: 'a> {
id: SourceId,
.map(|p| parse(p)).collect::<Result<Vec<_>, _>>());
let mut filter = |p: &Path| {
- let relative_path = p.relative_from(&root).unwrap();
+ let relative_path = util::without_prefix(p, &root).unwrap();
include.iter().any(|p| p.matches_path(&relative_path)) || {
include.len() == 0 &&
!exclude.iter().any(|p| p.matches_path(&relative_path))
// TODO: the `entry` has a mode we should be able to look at instead
// of just calling stat() again
- if fs::metadata(&file_path).map(|m| m.is_dir()) == Ok(true) {
+ if fs::metadata(&file_path).map(|m| m.is_dir()).unwrap_or(false) {
warn!(" found submodule {}", file_path.display());
- let rel = file_path.relative_from(&root).unwrap();
+ let rel = util::without_prefix(&file_path, &root).unwrap();
let rel = try!(rel.to_str().chain_error(|| {
human(format!("invalid utf-8 filename: {}", rel.display()))
}));
is_root: bool, filter: &mut F) -> CargoResult<()>
where F: FnMut(&Path) -> bool
{
- if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) {
+ if !fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false) {
if (*filter)(path) {
ret.push(path.to_path_buf());
}
-use std::error::{FromError, Error};
+use std::error::Error;
use std::ffi;
use std::fmt;
use std::io;
}
}
-impl FromError<Box<CargoError>> for CliError {
- fn from_error(err: Box<CargoError>) -> CliError {
+impl From<Box<CargoError>> for CliError {
+ fn from(err: Box<CargoError>) -> CliError {
CliError::from_boxed(err, 101)
}
}
macro_rules! from_error {
($($p:ty,)*) => (
- $(impl FromError<$p> for Box<CargoError> {
- fn from_error(t: $p) -> Box<CargoError> { Box::new(t) }
+ $(impl From<$p> for Box<CargoError> {
+ fn from(t: $p) -> Box<CargoError> { Box::new(t) }
})*
)
}
ffi::NulError,
}
-impl<E: CargoError> FromError<Human<E>> for Box<CargoError> {
- fn from_error(t: Human<E>) -> Box<CargoError> { Box::new(t) }
+impl<E: CargoError> From<Human<E>> for Box<CargoError> {
+ fn from(t: Human<E>) -> Box<CargoError> { Box::new(t) }
}
impl CargoError for semver::ReqParseError {}
impl CargoError for toml::Error {}
impl CargoError for toml::DecodeError {}
impl CargoError for url::ParseError {}
-impl CargoError for str::Utf8Error {}
impl CargoError for ffi::NulError {}
// =============================================================================
pub use self::errors::{process_error, internal_error, internal, human};
pub use self::errors::{Human, caused_human};
pub use self::paths::{join_paths, path2bytes, bytes2path, dylib_path};
-pub use self::paths::{normalize_path, dylib_path_envvar};
+pub use self::paths::{normalize_path, dylib_path_envvar, without_prefix};
pub use self::lev_distance::{lev_distance};
pub use self::hex::{to_hex, short_hash};
pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness};
use std::env;
-use std::ffi::{AsOsStr, OsString};
+use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf, Component};
use util::{human, internal, CargoResult, ChainError};
-pub fn join_paths<T: AsOsStr>(paths: &[T], env: &str) -> CargoResult<OsString> {
+pub fn join_paths<T: AsRef<OsStr>>(paths: &[T], env: &str) -> CargoResult<OsString> {
env::join_paths(paths.iter()).or_else(|e| {
- let paths = paths.iter().map(|p| {
- Path::new(p.as_os_str())
- }).collect::<Vec<_>>();
+ let paths = paths.iter().map(Path::new).collect::<Vec<_>>();
internal(format!("failed to join path array: {:?}", paths)).chain_error(|| {
human(format!("failed to join search paths together: {}\n\
Does ${} have an unterminated quote character?",
return ret;
}
+pub fn without_prefix<'a>(a: &'a Path, b: &'a Path) -> Option<&'a Path> {
+ let mut a = a.components();
+ let mut b = b.components();
+ loop {
+ let mut a2 = a.clone();
+ match (a2.next(), b.next()) {
+ (Some(x), Some(y)) if x == y => a = a2,
+ (Some(_), Some(_)) |
+ (None, Some(_)) => return None,
+ (Some(_), None) |
+ (None, None) => return Some(a.as_path()),
+ }
+ }
+}
+
#[cfg(unix)]
pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> {
use std::os::unix::prelude::*;
use std::collections::HashMap;
use std::env;
-use std::ffi::{OsString, AsOsStr};
+use std::ffi::{OsString, OsStr};
use std::fmt;
use std::path::Path;
use std::process::{Command, Output};
}
impl ProcessBuilder {
- pub fn arg<T: AsOsStr + ?Sized>(&mut self, arg: &T) -> &mut ProcessBuilder {
- self.args.push(arg.as_os_str().to_os_string());
+ pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut ProcessBuilder {
+ self.args.push(arg.as_ref().to_os_string());
self
}
- pub fn args<T: AsOsStr>(&mut self, arguments: &[T]) -> &mut ProcessBuilder {
+ pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut ProcessBuilder {
self.args.extend(arguments.iter().map(|t| {
- t.as_os_str().to_os_string()
+ t.as_ref().to_os_string()
}));
self
}
- pub fn cwd<T: AsOsStr + ?Sized>(&mut self, path: &T) -> &mut ProcessBuilder {
- self.cwd = path.as_os_str().to_os_string();
+ pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder {
+ self.cwd = path.as_ref().to_os_string();
self
}
- pub fn env<T: AsOsStr + ?Sized>(&mut self, key: &str,
- val: &T) -> &mut ProcessBuilder {
- self.env.insert(key.to_string(), Some(val.as_os_str().to_os_string()));
+ pub fn env<T: AsRef<OsStr>>(&mut self, key: &str,
+ val: T) -> &mut ProcessBuilder {
+ self.env.insert(key.to_string(), Some(val.as_ref().to_os_string()));
self
}
}
}
-pub fn process<T: AsOsStr + ?Sized>(cmd: &T) -> CargoResult<ProcessBuilder> {
+pub fn process<T: AsRef<OsStr>>(cmd: T) -> CargoResult<ProcessBuilder> {
Ok(ProcessBuilder {
- program: cmd.as_os_str().to_os_string(),
+ program: cmd.as_ref().to_os_string(),
args: Vec::new(),
cwd: try!(env::current_dir()).as_os_str().to_os_string(),
env: HashMap::new(),
use std::fmt;
use std::fs;
use std::path::{Path, PathBuf};
-use std::slice;
use std::str;
use toml;
use core::dependency::Kind;
use core::manifest::{LibKind, Profile, ManifestMetadata};
use core::package_id::Metadata;
-use util::{CargoResult, human, ToUrl, ToSemver, ChainError, Config};
+use util::{self, CargoResult, human, ToUrl, ToSemver, ChainError, Config};
/// Representation of the projects file layout.
///
config: &Config)
-> CargoResult<(Manifest, Vec<PathBuf>)> {
let manifest = layout.root.join("Cargo.toml");
- let manifest = match manifest.relative_from(config.cwd()) {
+ let manifest = match util::without_prefix(&manifest, config.cwd()) {
Some(path) => path.to_path_buf(),
None => manifest.clone(),
};
- let contents = try!(str::from_utf8(contents).chain_error(|| {
+ let contents = try!(str::from_utf8(contents).map_err(|_| {
human(format!("{} is not valid UTF-8", manifest.display()))
}));
let root = try!(parse(contents, &manifest));
package: Option<Box<TomlProject>>,
project: Option<Box<TomlProject>>,
profile: Option<TomlProfiles>,
- lib: Option<ManyOrOne<TomlLibTarget>>,
+ lib: Option<TomlLibTarget>,
bin: Option<Vec<TomlBinTarget>>,
example: Option<Vec<TomlExampleTarget>>,
test: Option<Vec<TomlTestTarget>>,
rpath: Option<bool>,
}
-#[derive(RustcDecodable)]
-pub enum ManyOrOne<T> {
- Many(Vec<T>),
- One(T),
-}
-
-impl<T> ManyOrOne<T> {
- fn as_slice(&self) -> &[T] {
- match *self {
- ManyOrOne::Many(ref v) => v,
- ManyOrOne::One(ref t) => slice::ref_slice(t),
- }
- }
-}
-
#[derive(RustcDecodable)]
pub struct TomlProject {
name: String,
// otherwise acceptable executable names are not used when inside of
// `src/bin/*`, but it seems ok to not build executables with non-UTF8
// paths.
-fn inferred_lib_target(name: &str, layout: &Layout) -> Vec<TomlTarget> {
+fn inferred_lib_target(name: &str, layout: &Layout) -> Option<TomlTarget> {
layout.lib.as_ref().map(|lib| {
- vec![TomlTarget {
+ TomlTarget {
name: name.to_string(),
path: Some(PathValue::Path(lib.clone())),
.. TomlTarget::new()
- }]
- }).unwrap_or(Vec::new())
+ }
+ })
}
fn inferred_bin_targets(name: &str, layout: &Layout) -> Vec<TomlTarget> {
// If we have a lib with a path, we're done
// If we have a lib with no path, use the inferred lib or_else package name
- let mut used_deprecated_lib = false;
let lib = match self.lib {
- Some(ref libs) => {
- match *libs {
- ManyOrOne::Many(..) => used_deprecated_lib = true,
- _ => {}
- }
- try!(libs.as_slice().iter().map(|t| {
- try!(validate_library_name(t));
- Ok(if layout.lib.is_some() && t.path.is_none() {
- TomlTarget {
- path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())),
- .. t.clone()
- }
- } else {
- t.clone()
- })
- }).collect::<CargoResult<Vec<_>>>())
+ Some(ref lib) => {
+ try!(validate_library_name(lib));
+ Some(if layout.lib.is_some() && lib.path.is_none() {
+ TomlTarget {
+ path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())),
+ .. lib.clone()
+ }
+ } else {
+ lib.clone()
+ })
}
None => inferred_lib_target(&project.name, layout),
};
project.links.clone(),
metadata,
profiles);
- if used_deprecated_lib {
- manifest.add_warning(format!("the [[lib]] section has been \
- deprecated in favor of [lib]"));
- }
if project.license_file.is_some() && project.license.is_some() {
manifest.add_warning(format!("warning: only one of `license` or \
`license-file` is necessary"));
}
}
-fn normalize(libs: &[TomlLibTarget],
+fn normalize(lib: &Option<TomlLibTarget>,
bins: &[TomlBinTarget],
custom_build: Option<PathBuf>,
examples: &[TomlExampleTarget],
.set_for_host(toml.plugin.unwrap_or(t2.for_host()));
}
- fn lib_targets(dst: &mut Vec<Target>, libs: &[TomlLibTarget],
- metadata: &Metadata) {
- let l = &libs[0];
+ fn lib_target(dst: &mut Vec<Target>, l: &TomlLibTarget,
+ metadata: &Metadata) {
let path = l.path.clone().unwrap_or_else(|| {
PathValue::Path(Path::new("src").join(&format!("{}.rs", l.name)))
});
let mut ret = Vec::new();
- if libs.len() > 0 && bins.len() > 0 {
- lib_targets(&mut ret, libs, metadata);
+ if let Some(ref lib) = *lib {
+ lib_target(&mut ret, lib, metadata);
bin_targets(&mut ret, bins,
&mut |bin| Path::new("src").join("bin")
.join(&format!("{}.rs", bin.name)));
- } else if libs.len() > 0 && bins.len() == 0 {
- lib_targets(&mut ret, libs, metadata);
- } else if libs.len() == 0 && bins.len() > 0 {
+ } else if bins.len() > 0 {
bin_targets(&mut ret, bins,
&mut |bin| Path::new("src")
.join(&format!("{}.rs", bin.name)));
use std::env;
use std::error::Error;
-use std::ffi::AsOsStr;
+use std::ffi::OsStr;
use std::fmt;
use std::fs;
use std::io::prelude::*;
self.root.join("target")
}
- pub fn process<T: AsOsStr + ?Sized>(&self, program: &T) -> ProcessBuilder {
+ pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
let mut p = process(program).unwrap();
p.cwd(&self.root()).env("HOME", &paths::home());
return p;
COMPILING, p.url(), RUNNING))
.with_stderr("\
thread '<main>' panicked at 'assertion failed: \
- `(left == right) && (right == left)` (left: \
+ `(left == right)` (left: \
`\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:14
")
use std::env;
use std::fs::{self, File};
use std::io::prelude::*;
+use std::thread;
use tempdir::TempDir;
use support::{project, execs, main_file, basic_bin_manifest};
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
});
-test!(opt_out_of_lib {
- let p = project("foo")
- .file("Cargo.toml", r#"
- lib = []
-
- [package]
- name = "foo"
- authors = []
- version = "0.0.1"
- "#)
- .file("src/lib.rs", "bad syntax")
- .file("src/main.rs", "fn main() {}");
- assert_that(p.cargo_process("build"), execs().with_status(0));
-});
-
test!(opt_out_of_bin {
let p = project("foo")
.file("Cargo.toml", r#"
assert_that(p.cargo_process("build"), execs().with_status(0));
});
-test!(deprecated_lib {
- let p = project("foo")
- .file("Cargo.toml", r#"
- [package]
- name = "foo"
- authors = []
- version = "0.0.1"
-
- [[lib]]
- name = "foo"
- "#)
- .file("src/foo.rs", "");
- assert_that(p.cargo_process("build"),
- execs().with_status(0)
- .with_stderr("\
-the [[lib]] section has been deprecated in favor of [lib]\n"));
-});
-
test!(freshness_ignores_excluded {
let foo = project("foo")
.file("Cargo.toml", r#"
assert_that(&p.bin("foo"), existing_file());
if cfg!(windows) {
// On windows unlinking immediately after running often fails, so sleep
- use std::time::duration::Duration;
- ::sleep(Duration::milliseconds(100));
+ thread::sleep_ms(100);
}
fs::remove_file(&p.bin("foo")).unwrap();
assert_that(p.cargo("run"),
let out = env::var("OUT_DIR").unwrap();
assert!(out.starts_with(r"{0}"));
- assert_eq!(fs::metadata(&out).map(|m| m.is_dir()), Ok(true));
+ assert!(fs::metadata(&out).map(|m| m.is_dir()).unwrap_or(false));
let _host = env::var("HOST").unwrap();
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::Path;
-use std::time::Duration;
+use std::thread;
use git2;
use support::{ProjectBuilder, project, execs, main_file, path2url};
add(&repo);
commit(&repo);
- ::sleep(Duration::milliseconds(1000));
+ thread::sleep_ms(1000);
// By default, not transitive updates
println!("dep1 update");
add(&repo);
commit(&repo);
- ::sleep(Duration::milliseconds(1000));
+ thread::sleep_ms(1000);
let rev = repo.revparse_single("HEAD").unwrap().id();
add(&repo);
commit(&repo);
- ::sleep(Duration::milliseconds(1000));
+ thread::sleep_ms(1000);
// Update the dependency and carry on!
println!("update");
assert_that(project.cargo("update").arg("-v"),
}).unwrap();
foo.root().move_into_the_past().unwrap();
- ::sleep(Duration::milliseconds(1000));
+ thread::sleep_ms(1000);
assert_that(foo.cargo("build"),
execs().with_status(0)
use std::fs::{self, File};
use std::io::prelude::*;
-use std::time::Duration;
+use std::thread;
use support::{project, execs, main_file};
use support::{COMPILING, RUNNING};
//
// We base recompilation off mtime, so sleep for at least a second to ensure
// that this write will change the mtime.
- ::sleep(Duration::seconds(1));
+ thread::sleep_ms(1000);
File::create(&p.root().join("baz/src/baz.rs")).unwrap().write_all(br#"
pub fn baz() { println!("hello!"); }
"#).unwrap();
COMPILING, p.url())));
// Make sure an update to bar doesn't trigger baz
- ::sleep(Duration::seconds(1));
+ thread::sleep_ms(1000);
File::create(&p.root().join("bar/src/bar.rs")).unwrap().write_all(br#"
extern crate baz;
pub fn bar() { println!("hello!"); baz::baz(); }
let mut f = File::open(&upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
- assert_eq!(f.read(&mut sz), Ok(4));
+ assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) |
((sz[1] as u32) << 8) |
((sz[2] as u32) << 16) |
---- test_hello stdout ----
<tab>thread 'test_hello' panicked at 'assertion failed: \
- `(left == right) && (right == left)` (left: \
+ `(left == right)` (left: \
`\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:12
macro_rules! f6( () => ({(f5!()) + (f5!())}) );
macro_rules! f7( () => ({(f6!()) + (f6!())}) );
macro_rules! f8( () => ({(f7!()) + (f7!())}) );
- macro_rules! f9( () => ({(f8!()) + (f8!())}) );
- macro_rules! f10( () => ({(f9!()) + (f9!())}) );
- macro_rules! f11( () => ({(f10!()) + (f10!())}) );
pub fn bar() {
- f11!();
+ f8!();
}
"#);
assert_that(p.cargo_process("test"),
-#![feature(io, convert, thread_sleep)]
-#![feature(std_misc, io, fs, fs_ext, path_ext, fs_time, fs_walk)]
+#![feature(fs, fs_ext, path_ext, fs_time, fs_walk)]
extern crate rustc_serialize;
extern crate cargo;
mod test_cargo_test;
mod test_cargo_version;
mod test_shell;
-
-fn sleep(dur: std::time::Duration) {
- std::thread::sleep(dur)
-}